<template>
	<view>
		<view class="top">
			<view v-if="res.status == 0">
				<view v-if="res.paytype == 3">
					货到付款，等待发货
				</view>
				<view v-else>
					等待付款
				</view>
			</view>
			<view v-else-if="res.status == 1">
				<text v-if="res.sendtype >0">部分商品已发货</text>
				<text v-else>买家已付款</text>
				<text v-if="res.ccard !=0&&res.ccard != null">(充值中)</text>
			</view>
			<view v-else-if="res.status == 2">
				<text>卖家已发货</text>
			</view>
			<view v-else-if="res.status == 3">
				<text>交易完成</text><text v-if="res.ccard !=0 &&res.ccard != null">(充值完成)</text>
			</view>
			<view v-else-if="res.static == -1">
				<text>交易关闭</text>
			</view>
			<view style="font-size: 24upx;" v-cloak>
				订单金额：{{res.goodsprice-res.tongduibao-res.jindou}}
			</view>
		</view>
		<view class="list">
			<view class="uni-list">
				<view v-if="res.express" class="uni-list-cell" hover-class="uni-list-cell-hover">
					<view class="uni-list-cell-navigate uni-navigate-right uni-media-list" @click="jump()">
						<view class="uni-media-list-logo" style="width: 40upx;">
							<image src="../../../static/orderadd.png" style="width: 32upx;height: 32upx;margin: 26upx auto;"></image>
						</view>
						<view class="uni-media-list-body">
							<view class="uni-media-list-text-top" style="font-size: 28upx;color: #f55;" v-if="res.express_step">{{res.express_step}}</view>
							<view class="uni-media-list-text-bottom uni-ellipsis" v-if="res.express_time">{{res.express_time}}</view>
						</view>
					</view>
				</view>
				<view class="uni-list-cell">
					<view class="uni-media-list">
						<view class="uni-media-list-logo" style="width: 40upx;">
							<image src="../../../static/dingwei.png" style="width: 32upx;height: 32upx;margin: 26upx auto;"></image>
						</view>
						<view class="uni-media-list-body">
							<view class="uni-media-list-text-top" style="font-size: 28upx;" v-if="res.address_realname">{{res.address_realname}} {{res.address_mobile}}</view>
							<view class="uni-media-list-text-bottom uni-ellipsis" v-if="res.address_province">{{res.address_province}}{{res.address_city}}{{res.address_area}} {{res.addressstreet}} {{res.address_address}}</view>
						</view>
					</view>
				</view>
			</view>
			
		</view>
		<view class="goods" style="background: #fff;">
			<view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(value,key) in res.goods" :key="key">
				<view class="uni-media-list">
					<view class="uni-media-list-logo" style="width: 160upx;height: 160upx;">
						<image :src="value.thumb" style="width: 160upx;height: 160upx;" ></image>
					</view>
					<view class="uni-media-list-body" style="height: 160upx;">
						<view class="uni-media-list-text-top" style="font-size: 28upx;" v-if="value.title">{{value.title}}</view>
						<view class="uni-media-list-text-bottom uni-ellipsis" v-if="value.optiontitle">{{value.optiontitle}}</view>
					</view>
				</view>
			</view>
			
		</view>
		<view class="webkit" style="padding: 12upx 24upx;background: #fff;margin-bottom: 20upx;">
			<view class="flex">运费</view>
			<view v-if="res.dispatchprice">¥{{res.dispatchprice}}</view>
		</view>
		<view class="detail">
			<view><text>订单编号</text><text v-if="res.ordersn">{{res.ordersn}}</text></view>
			<view><text>创建时间</text><text v-if="res.createtime">{{res.createtime}}</text></view>
			<view v-if="res.status >=1 &&res.paytime >0"><text>支付时间</text><text v-if="res.paytime">{{res.paytime}}</text></view>
			<view v-if="res.status >=2||res.status>=1 &&res.sendtype >0"><text>发货时间	</text><text v-if="res.sendtime">{{res.sendtime}}</text></view>
		</view>
		
		<!-- <view v-if="res.userdeleted == 0">
			<view style="position: fixed;bottom: 0upx;left: 0;height: 110upx;background-color:#ffffff;line-height: 100upx;width: 100%;z-index: 999999;">
				<view style="padding: 10upx 20upx;height: 50upx;line-height: 50upx;background-color: #cccccc;right: 40upx;border-radius: 20upx;color: #333333;margin-top: 20upx;margin-right: 20upx;display: inline-block;" @click="jumptorefund(res.status)" v-if="res.refundstate == 0 && res.status == 1 && res.canrefund">
					申请退款
				</view>
				<view style="padding: 10upx 20upx;height: 50upx;line-height: 50upx;background-color: #cccccc;right: 40upx;border-radius: 20upx;color: #333333;margin-top: 20upx;margin-right: 20upx;display: inline-block;" v-if="res.refundstate == 0 && res.status != 1 && res.canrefund" @click="jumptorefund(res.status)" >
					申请售后
				</view>
				<view style="padding: 10upx 20upx;height: 50upx;line-height: 50upx;background-color: #cccccc;right: 40upx;border-radius: 20upx;color: #333333;margin-top: 20upx;margin-right: 20upx;display: inline-block;" @click="jumptorefund(res.status)" v-if="res.refundstate != 0 && res.canrefund && res.status == 1">
					查看申请退款进度
				</view>
				<view style="padding: 10upx 20upx;height: 50upx;line-height: 50upx;background-color: #cccccc;right: 40upx;border-radius: 20upx;color: #333333;margin-top: 20upx;margin-right: 20upx;display: inline-block;" @click="jumptorefund(res.status)" v-if="res.refundstate != 0 && res.canrefund && res.status != 1">
					查看申请售后进度
				</view>
				<view style="padding: 10upx 20upx;height: 50upx;line-height: 50upx;background-color: #cccccc;right: 40upx;border-radius: 20upx;color: #333333;margin-top: 20upx;margin-right: 20upx;display: inline-block;" @click="delorder" v-if="res.status == -1 || res.status == 3">
					删除订单
				</view>
				<view style="padding: 10upx 20upx;height: 50upx;line-height: 50upx;background-color: #cccccc;right: 40upx;border-radius: 20upx;color: #333333;margin-top: 20upx;margin-right: 20upx;display: inline-block;"  v-if="res.iscomment == 1 && res.status == 3" @click="twice_add">
					追加评价
				</view>
				<view style="padding: 10upx 20upx;height: 50upx;line-height: 50upx;background-color: #cccccc;right: 40upx;border-radius: 20upx;color: #333333;margin-top: 20upx;margin-right: 20upx;display: inline-block;" v-if="res.iscomment == 0 && res.status == 3 && !res.closecomment">
					评价
				</view>
				<view style="padding: 10upx 20upx;height: 50upx;line-height: 50upx;background-color: #cccccc;right: 340upx;border-radius: 20upx;color: #333333;margin-top: 20upx;margin-right: 20upx;display: inline-block;" v-if="res.status == 2">
					确认收货
				</view>
				<view style="padding: 10upx 20upx;height: 50upx;line-height: 50upx;background-color: #cccccc;right: 340upx;border-radius: 20upx;color: #333333;margin-top: 20upx;margin-right: 20upx;display: inline-block;" @tap="del_apply" v-if="res.refundstate> 0 && res.status != 5">
					取消申请
				</view>
				
				<view style="padding: 10upx 20upx;height: 50upx;line-height: 50upx;background-color: #cccccc;right: 340upx;border-radius: 20upx;color: #333333;margin-top: 20upx;margin-right: 20upx;display: inline-block;" @tap="del_orders" v-if="res.status == 0">
					取消订单
				</view>
				<view style="position: absolute;bottom: 110upx;left: 400upx;background-color: #ffffff;border: 1upx solid #EEEEEE;z-index: 9999;" :style="{display: show_none}">
					<view v-for="(arr,index) in arrs" :key=index @click.stop="show_hid(index)" style="height:50upx;line-height:50upx;color:#888888;font-size: 30upx;">
						{{arr}}
					</view>
				</view>
				<view style="padding: 10upx 20upx;height: 50upx;line-height: 50upx;background-color: #cccccc;right: 340upx;border-radius: 20upx;color: #333333;margin-top: 20upx;margin-right: 20upx;display: inline-block;"  v-if="res.paytype != 3 && !res.ispeerpay && res.status == 0">
					支付订单
				</view>
				<view style="padding: 10upx 20upx;height: 50upx;line-height: 50upx;background-color: #cccccc;right: 340upx;border-radius: 20upx;color: #333333;margin-top: 20upx;margin-right: 20upx;display: inline-block;"  v-if="((res.paytype != 3 || res.ispeerpay) && res.status == 0) || ((res.paytype == 3 || !res.ispeerpay) && res.status == 0)">
					代付订单
				</view>
			</view>
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				res:[],
				orderid:0,
				openid:''
			};
		},
		onLoad:function(e){
			uni.showLoading()
			this.orderid = e.id
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data
					this.setAjax()
				},
				fail: () => {
					uni.navigateTo({
						url: '../../login/login'
					});
				}
			});
		},methods:{
			setAjax(){
				uni.request({
					url: 'http://hszj.hongshantang696.com//app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=order.detail&app=1&id='+this.orderid,
					method: 'POST',
					data: {'openid':this.openid},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						uni.hideLoading()
						this.res = res.data
					},
					fail: () => {},
					complete: () => {}
				});
			},
			delorder() {
				var _this = this
				uni.showModal({
					content: '是否删除订单?',
					success() {
						if(confirm) {
							// console.log(_this.orderid)
							// console.log(_this.openid)
							uni.request({
								url: 'http://hszj.hongshantang696.com//app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=order.op.delete&app=1',
								method: 'POST',
								data: {
									id: _this.orderid,
									openid: _this.openid,
									userdeleted: 1
									},
								header:{'Content-Type':'application/x-www-form-urlencoded'},
								success: res => {
									console.log(res)
									if (res.data.result.status == 1) {
										uni.showToast({
											title : '删除成功',
											icon: none
										})
										uni.reLaunch({
											url: '../../order/order?index=3'
										})
									} 
									
									uni.hideLoading()
								},
								fail: () => {},
								complete: () => {}
							});
						}
					}
					
				})
			},
			jump(){
				uni.navigateTo({
					url: '../express/express?id='+this.orderid
				});
			},
			jumptorefund(status){
				uni.navigateTo({
					url: '../refund/refund?status='+ status + '&id=' + this.orderid
				});
			},
			twice_add() {
				uni.navigateTo({
					url: '../comment/comment?id=' + this.orderid
				});
			},
			del_orders() {
				this.show_none = 'block'
			},
			show_hid(index) {
				this.show_none = 'none'
				if(this.arrs[index] == '不取消了') {
					
					return
				}
				uni.request({
					url: 'http://hszj.hongshantang696.com//app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=order.op.cancel&app=1',
					method: 'POST',
					data: {
						openid:this.openid,
						id: this.orderid,
						remark: this.arrs[index]
						},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						console.log(res)
						if(res.data.status == 0) {
							uni.showToast({
								title: res.data.result.message,
								icon:"none"
							})
							return
						}
						// 以下为取消订单成功内容
						
					},
					fail: () => {},
					complete: () => {}
				});
				console.log(this.arrs[index])
			},
			del_apply(){
				var _this = this
				uni.request({
					url: 'http://hszj.hongshantang696.com//app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=order.refund.cancel&app=1',
					method: 'POST',
					data: {
						openid:this.openid,
						id: this.orderid
						},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						console.log(res)
						if(res.data.status == 0) {
							uni.showToast({
								title: res.data.result.message,
								icon:"none"
							})
							return
						}
						uni.showToast({
							title: '取消申请成功',
							icon:"none"
						})
						_this.setAjax()
						// 以下为取消订单成功内容
						
					},
					fail: () => {},
					complete: () => {}
				});
			},
		}
	}
</script>

<style>.top{height:200upx;background:-moz-linear-gradient(left,#EB2E15 0%,#EB2E15 100%);background:-webkit-linear-gradient(left,#EB2E15 0%,#EB2E15 100%);background:-o-linear-gradient(left,#EB2E15 0%,#EB2E15 100%);background:-ms-linear-gradient(left,#EB2E15 0%,#EB2E15 100%);background:linear-gradient(to right,#EB2E15 0%,#EB2E15 100%);-webkit-box-flex:1;-webkit-flex:1;-ms-flex:1;flex:1;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;flex-direction:column;align-items:center;-webkit-align-items:center;justify-content:center;padding:0 24upx;font-size:26upx;line-height:48upx;}.top view{color:#fff;font-size:36upx;}.list{margin-bottom:20upx;}.detail view{line-height:40upx;height:40upx;}.detail view text{font-size:24upx;color:#999;}.detail view text:first-child{margin-right:28upx;}.detail{padding:0 24upx;}</style>